package cn.school.servlet;

import cn.school.entity.Subject;
import cn.school.service.SubjectService;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet( value = "/subjectServlet")
public class SubjectServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        response.setContentType("text/html;charset=UTF-8");
//        PrintWriter out=response.getWriter();

        List<Subject> all = SubjectService.INST.findALL();
        //1:jsp中如何拿到all
        request.setAttribute("subjects",all);
        //转发！！！！！！！！！！！！！！！！！！
        request.getRequestDispatcher("/WEB-INF/jsp/subject/subject.jsp").forward(request,response);
        //2:怎么跳到到这个jsp
//        out.write("<html>");
//        out.write("<head>");
//        out.write("</head>");
//        out.write("<body>");
//        out.write("<a href='addsubject.jsp'>新增课程</a>");
//        all.forEach(x->{
//            out.write("<div>");
//            out.write("ID:"+x.getId()+"课程名"+x.getSubjectname()+"课时"+x.getClasshour()+"班级id"+x.getGradeId());
//            out.write("</div>");
//        });
//        out.write("</body>");
//
//        out.write("</html>");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
